﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Entity;
using BAL;
using Common;
namespace Web
{
    public partial class UpdatePassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ////this.txtOldPassword.Attributes.Add("onblur", "checkOldPassword()");
            ////this.txtNewPassword.Attributes.Add("onblur","");
            ////this.txtRePassword.Attributes.Add("onblur","");
            //////Response.Write("<script>alert(" + Session["userid"]+ ");</script>");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int uid = 0;
            if (Session["userid"] == null)
            {

            }
            else 
            {
                uid = Convert.ToInt32(Session["userid"]);
                string oldPassword = "";
                if (txtOldPassword.Text.Trim() == "")
                {
                    Response.Write("<script>alert('原始密码不允许为空');</script>");
                    return;
                }
                else if (txtOldPassword.Text.Trim().Length < 6)
                {
                    Response.Write("<script>alert('密码长度至少6位');</script>");
                    return;
                }
                else if (Users.GetUserInfoById(uid)==null)
                {
                    Response.Write("<script>alert('原始密码不正确');</script>");
                    return;
                }
                string newPassword="";
                if (txtNewPassword.Text.Trim()=="")
                {
                    Response.Write("<script>alert('新密码不允许为空');</script>");
                    return;
                }
                else if (txtNewPassword.Text.Trim().Length < 6)
                {
                    Response.Write("<script>alert('新密码至少6位');</script>");
                    return;
                }
                else 
                {
                    newPassword = txtNewPassword.Text.Trim();
                }
                string rePassword = "";
                if (txtRePassword.Text.Trim() == "")
                {
                    Response.Write("<script>alert('确认密码不允许为空');</script>");
                    return;
                }
                else if (txtRePassword.Text.Trim().Length<6)
                {
                    Response.Write("<script>alert('确认密码至少6位');</script>");
                    return;
                }
                else if (newPassword != txtRePassword.Text.Trim())
                {
                    Response.Write("<script>alert('两次输入密码不一致');</script>");
                    return;
                }
                else {
                    rePassword = txtRePassword.Text.Trim();
                    UserInfo User_Info = Users.GetT1(uid);
                    User_Info.PassWord = Utility.MD5(rePassword);
                    Users.Edit(User_Info);
                   // Response.Write("<script>alert('修改密码成功');</script>");
                    //.ShowJsAlertAndCloseRefresh(String strAlert, this)
                    Utility.ShowJsAlertAndCloseRefresh("修改密码成功",this);
                }

            }
            
        }

    }
}
